package com.hospital.serviceImpl;

import com.hospital.dao.UserMapper;
import com.hospital.entity.User;
import com.hospital.entity.UserDepartment;
import com.hospital.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class UserServiceImpl implements UserService {
    @Autowired
    private UserMapper userMapper;

    /**
     * 登录方法
     *
     * @param username 用户名
     * @return 登录信息
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public User login(String username) {
        User user = userMapper.login(username);
        return user;
    }

    /**
     * 修改密码方法
     *
     * @param username 用户名
     * @param password 密码
     * @return 修改状态
     */
    @Override
    public Integer updatePassword(String username, String password) {
        Integer state = userMapper.updatePassword(username, password);
        return state;
    }

    /**
     * 用户查询
     *
     * @param username 用户名
     * @return 用户信息
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public User SelectUser(String username) {
        User user = userMapper.SelectUser(username);
        return user;
    }

    /**
     * 分页查所有
     *
     * @param page    当前页
     * @param pageNum 每页显示条数
     * @return 集合中的user对象
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<User> SelectAll(Integer page, Integer pageNum) {
        List<User> users = userMapper.SelectAll(page, pageNum);
        return users;
    }

    /**
     * 查所有数量
     *
     * @return 所有数量
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public Integer SelectAllCount() {
        Integer count = userMapper.SelectAllCount();
        return count;
    }

    /**
     * 根据主键查询用户信息
     *
     * @param id 用户表主键
     * @return 用户信息
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public User SelectById(Integer id) {
        User user = userMapper.SelectById(id);
        return user;
    }

    /**
     * 修改方法
     *
     * @param user 用户对象
     * @return 修改状态
     */
    @Override
    public Integer Update(User user) {
        Integer state = userMapper.Update(user);
        return state;
    }

    /**
     * 批量删除方法
     *
     * @param id 批量删除id
     * @return 删除状态
     */
    @Override
    public int bulkDelete(List<Integer> id) {
        int state = userMapper.BulkDelete(id);
        return state;
    }

    /**
     * 条件查询
     *
     * @param page    当前页
     * @param pageNum 每页显示条数
     * @param user    当前user对象
     * @return 集合中的user对象
     */
    @Transactional(propagation = Propagation.SUPPORTS, readOnly = true)
    @Override
    public List<User> SelectByUserLike(Integer page, Integer pageNum, User user) {
        List<User> users = userMapper.SelectByUserLike(page, pageNum, user);
        return users;
    }

    /**
     * 条件查询数量
     *
     * @return 数量
     */
    @Override
    public Integer SelectByUserLikeCount(User user) {
        Integer count = userMapper.SelectByUserLikeCount(user);
        return count;
    }

    /**
     * 添加用户方法
     *
     * @param user 用户对象
     * @return 添加状态
     */
    @Override
    public Integer Insert(User user) {
        Integer state = userMapper.Insert(user);
        return state;
    }

    /**
     * 根据用户姓名查询方法
     *
     * @param name 用户姓名
     * @return 用户信息
     */
    @Override
    public List<User> SelectByUserName(String name) {
        List<User> users = userMapper.SelectByUserName(name);
        return users;
    }
}
